﻿using System.Windows;
using System.Windows.Controls;

namespace WebsiteLoadTool.Controls
{
    public partial class StatusIndicator : UserControl
    {
        public StatusIndicator()
        {
            InitializeComponent();
        }

        public ResultStatusEnum Status
        {
            get { return (ResultStatusEnum)GetValue(StatusProperty); }
            set { SetValue(StatusProperty, value); }
        }

        public static readonly DependencyProperty StatusProperty = DependencyProperty.Register("Status", typeof(ResultStatusEnum), typeof(StatusIndicator), new UIPropertyMetadata(ResultStatusEnum.None, StatusPropertyChanged));

        private static void StatusPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            StatusIndicator statusIndicator = (StatusIndicator)sender;

            switch ((ResultStatusEnum)args.NewValue)
            {
                case ResultStatusEnum.None:
                    VisualStateManager.GoToState(statusIndicator, "None", true);
                    break;

                case ResultStatusEnum.InProgress:
                    VisualStateManager.GoToState(statusIndicator, "InProgress", true);
                    break;

                case ResultStatusEnum.Success:
                    VisualStateManager.GoToState(statusIndicator, "Success", true);
                    break;

                case ResultStatusEnum.Failed:
                    VisualStateManager.GoToState(statusIndicator, "Failed", true);
                    break;

                case ResultStatusEnum.TimedOut:
                    VisualStateManager.GoToState(statusIndicator, "TimedOut", true);
                    break;
            }
        }
    }
}
